<?php

class AFForm extends AFQueriable
{
	private $values = array();

	public function __construct($values)
	{
		$this->values = $values;
	}

	public function getAll()
	{
		return $this->values;
	}

	public function queryHandler($key, $arguments)
	{
		return isset($this->values[$key]) ? $this->values[$key] : NULL;
	}
}

class AFFormsModule extends AFModule
{
	private $forms = array();
	public function __init()
	{
		foreach($_REQUEST as $key=>$value)
		{
//			preg_match_all('/^_afform_$/', $key, $out);
		}
	}

	public function getForm($name)
	{
		// Some caching
		if(isset($this->forms[$name]))
		{
			return $this->forms[$name];
		}

		$values = array();
		foreach($_REQUEST as $key => $value)
		{
			if(strpos($key, '_'.$name.'_form_') !== FALSE)
			{
//				echo $key;
				$paramName = substr($key, strlen($name)+7);
				if(!$paramName)
				{
					continue;
				}
				$values[$paramName] = $_REQUEST[$key];
			}
		}

		$form = new AFForm($values);
		$this->forms[$name] = $form;
		return $form;
	}
}

?>
